package com.example.service;

import com.example.dao.LoginDao;
import com.example.entity.LoginEntity;
import com.example.exception.LoginException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

@Service
public class LoginServiceImpl implements  LoginService {
    @Autowired
    private LoginDao dao;

    @Override
    public void addUser(@RequestBody LoginEntity entity) {
        //先不判断，试试约束有没有用，有用再加
        try {
            dao.addUser(entity);
        } catch (Exception e) {
            e.printStackTrace();
            throw LoginException.createException("1116");
        }
    }

    @Override
    public LoginEntity queryByName(String name) {
        return dao.queryByName(name);
    }

    @Override
    public void deleteUser(LoginEntity entity) {
        dao.deleteUser(entity);
    }

    @Override
    public LoginEntity getUserById(Long id) {
        return dao.getUserById(id);
    }

    @Override
    public String getUserNameById(Long id) {
        return dao.getUserNameById(id,"name");
    }
}
